package com.sevenwonders.core;

import java.util.List;

import com.sevenwonders.R;
import com.sevenwonders.util.Helper;

public enum Resource {
    CLAY("Clay", Type.RAW, R.drawable.resource_clay),
    ORE("Ore", Type.RAW, R.drawable.resource_ore),
    WOOD("Wood", Type.RAW, R.drawable.resource_wood),
    STONE("Stone", Type.RAW, R.drawable.resource_stone),
    GLASS("Glass", Type.MANUFACTURED, R.drawable.resource_glass),
    CLOTH("Cloth", Type.MANUFACTURED, R.drawable.resource_cloth),
    PAPYRUS("Papyrus", Type.MANUFACTURED, R.drawable.resource_papyrus),
    WOOD_CLAY("Wood/Clay", Type.RAW),
    STONE_CLAY("Stone/Clay", Type.RAW),
    CLAY_ORE("Clay/Ore", Type.RAW),
    STONE_WOOD("Stone/Wood", Type.RAW),
    WOOD_ORE("Wood/Ore", Type.RAW),
    ORE_STONE("Ore/Stone", Type.RAW),
    RAW("Clay/Ore/Stone/Wood", Type.RAW),
    MANUFACTURED("Glass/Cloth/Papyrus", Type.MANUFACTURED);

    public enum Type {
        RAW,
        MANUFACTURED;
    }

    private String name;
    private Type type;
    private int[] ids;

    private Resource(String name, Type type, int... ids) {
        this.name = name;
        this.type = type;
        this.ids = ids;
    }

    public String getName() {
        return name;
    }

    public Type getType() {
        return type;
    }

    public int[] getIds() {
        return ids;
    }

    int indexInList(List<Resource> resources) {
        if (!Helper.isEmpty(resources)) {
            for (int i = 0; i < resources.size(); i++) {
                Resource r = resources.get(i);
                if (r.getName()
                    .indexOf(name) > -1) {
                    return i;
                }
            }
        }

        return -1;
    }
}
